import request from '@/utils/request'
import type { ApiResponse, PageParams, PageResult, Role, MenuPermissionVO } from './types'

// 获取所有角色（不分页）
export function getRoleList() {
  return request.get<ApiResponse<Role[]>>('/role/all')
}

// 分页查询角色列表
export function getRolePageList(params?: PageParams & { keyword?: string; status?: string }) {
  return request.get<ApiResponse<PageResult<Role>>>('/role/list', { params })
}

// 获取角色详情
export function getRoleInfo(id: number) {
  return request.get<ApiResponse<Role>>(`/role/${id}`)
}

// 添加角色
export function addRole(data: Partial<Role>) {
  return request.post<ApiResponse>('/role', data)
}

// 更新角色
export function updateRole(data: Partial<Role>) {
  return request.put<ApiResponse>('/role', data)
}

// 删除角色
export function deleteRole(id: number) {
  return request.delete<ApiResponse>(`/role/${id}`)
}

// 批量删除角色
export function batchDeleteRole(ids: number[]) {
  return request.delete<ApiResponse>('/role/batch', { data: { ids } })
}

// 获取角色菜单
export function getRoleMenus(roleId: number) {
  return request.get<ApiResponse<number[]>>(`/role/${roleId}/menus`)
}

// 分配角色菜单
export function assignRoleMenus(roleId: number, menuIds: number[]) {
  return request.post<ApiResponse>(`/role/${roleId}/menus`, menuIds)
}

// 获取角色菜单权限
export function getRoleMenuPermissions(roleId: number) {
  return request.get<ApiResponse<MenuPermissionVO[]>>(`/role/${roleId}/menu-permissions`)
} 